package org.stone.project.logInterface.utils;

import cn.hutool.extra.spring.SpringUtil;
import org.stone.project.common.utils.ThreadTimeSnap;
import org.stone.project.logInterface.pojo.po.MethodLog;
import org.stone.project.logInterface.pojo.po.RequestLog;
import org.stone.project.logInterface.service.DbLogService;
import org.stone.project.logInterface.service.FileLogService;

/**
 * 日志工具
 */
public class LogUtil {
    /**
     * 添加持久化方法日志
     * @param methodLog
     */
    public static void addMethodLog(MethodLog methodLog){
        methodLog.setCreateTime(ThreadTimeSnap.getRecordTime());
        getDbLogService().addMethodLog(methodLog);
    }

    /**
     * 添加持久化请求日志
     * @param requestLog
     */
    public static void addReuqestLog(RequestLog requestLog){
        requestLog.setCreateTime(ThreadTimeSnap.getRecordTime());
        getDbLogService().addRequestLog(requestLog);
    }


    /**
     * 添加普通文件日志
     */
    public static void addSysInfoLog(String msg,Object... msgs){
        getFileLogService().addLogInfoTxt(msg,msgs);
    }

    /**
     * 添加警告文件日志
     */
    public static void addSysWarnLog(String msg,Object... msgs){
        getFileLogService().addLogWarnTxt(msg,msgs);
    }

    /**
     * 添加错误文件日志
     */
    public static void addSysErrLog(String msg,Object... msgs){
        getFileLogService().addLogErrTxt(msg,msgs);
    }








    private static FileLogService getFileLogService(){
        return SpringUtil.getBean(FileLogService.class);
    }


    private static DbLogService getDbLogService(){
        return SpringUtil.getBean(DbLogService.class);
    }
}
